package com.example.books.program

/**
 * @title: Singleton
 * @projectName bigdata
 * @Version: 1.0
 * @description: 单例类测试
 * @author leali
 * @date 2022/5/31 23:51
 */
class Singleton(val color: String) {
  println(s"Creating $this")

  override def toString: String = s"marker color $color"

}

object MarkerFactory {
  private val markers: Map[String, Singleton] = Map(
    "red" -> new Singleton("red"),
    "blue" -> new Singleton("blue"),
    "green" -> new Singleton("green")
  )

  def getMarker(color: String): Singleton = {
    //    if(markers.contains(color)) markers(color) else null
    markers.getOrElse(color, null)
  }
}